unit PacocMaths;

interface

uses
  Math, Windows;

type
  TBox = record
    x1, y1, x2, y2: Integer;
  end;
  TIntegerArray = Array of Integer;
  TExtendedArray = Array of Extended;

function  SqrRoot(e : Extended)                       : Extended;
function  Square(e : Extended)                        : Extended;
function  Rndm(I: Integer)                            : Integer;
function  RndmRange(iFrom, iTo: Integer)              : Integer;
function  Pow(Base, Exponent: Extended)               : Extended;
function  IntPow(Base: Extended; Exponent: Integer)   : Extended;
function  Maximum(N1, N2: Extended)                   : Extended;
function  Minimum(N1, N2: Extended)                   : Extended;
function  iMaximum(N1, N2: Integer)                   : Integer;
function  iMinimum(N1, N2: Integer)                   : Integer;
function  Int(E: Extended)                            : Integer;
function  Flr(E: Extended)                            : Integer;
function  Trnc(E: Extended)                           : Integer;
function  Cel(E: Extended)                            : Integer;
function  Pi                                          : Extended;
function  AbsVal(E: Extended)                         : Extended;
function  iAbsVal(I: Integer)                         : Integer;
function  Distance(x1, y1, x2, y2: Integer)           : Integer;
function  IntInBox(x, y: Integer; Box: TBox)          : Boolean;
function  PointInBox(P: TPoint; Box: TBox)            : Boolean;
function  PointToBox(P1, P2: TPoint)                  : TBox;
function  Point(x, y: Integer)                        : TPoint;
function  IntToBox(x1, y1, x2, y2: Integer; Box: TBox): TBox;
function  AMin(Data: TIntegerArray)                   : Integer;
function  AMinE(Data: TExtendedArray)                 : Extended;
function  AMax(Data: TIntegerArray)                   : Integer;
function  AMaxE(Data: TExtendedArray)                 : Extended;

implementation

function SqrRoot(e : Extended): Extended;
begin
  result := sqrt(e);
end;

function Square(e : Extended): Extended;
begin
  result := sqr(e);
end;

function Rndm(I: Integer): Integer;
begin
  Result:= Random(I);
end;

function RndmRange(iFrom, iTo: Integer): Integer;
begin
  Result:= RandomRange(iFrom, iTo);
end;

function Pow(Base, Exponent: Extended): Extended;
begin
  Result:= Power(Base, Exponent);
end;

function IntPow(Base: Extended; Exponent: Integer): Extended;
begin
  Result:= IntPower(Base, Exponent); 
end;

function Maximum(N1, N2: Extended): Extended;
begin
  Result:= Max(N1, N2);
end;

function Minimum(N1, N2: Extended): Extended;
begin
  Result:= Min(N1, N2);
end;

function iMaximum(N1, N2: Integer): Integer;
begin
  Result:= Max(N1, N2);
end;

function iMinimum(N1, N2: Integer): Integer;
begin
  Result:= Min(N1, N2);
end;

function Int(E: Extended): Integer;
begin
  Result:= Round(E);
end;

function Flr(E: Extended): Integer;
begin
  Result:= Floor(E);
end;

function Trnc(E: Extended): Integer;
begin
  Result:= Floor(E);
end;

function Cel(E: Extended): Integer;
begin
  Result:= Ceil(E);
end;

function Pi: Extended;
begin
  Result:= 3.14159265358979;
end;

function AbsVal(E: Extended): Extended;
begin
  Result:= Abs(E);
end;

function iAbsVal(I: Integer): Integer;
begin
  Result:= Abs(I);
end;

function Distance(x1, y1, x2, y2: Integer): Integer;
begin
  Result:= Round(Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
end;

function IntInBox(x, y: Integer; Box: TBox): Boolean;
begin
  Result:= False;
  if(x >= Box.x1)then
    if(x <= Box.x2)then
      if(y >= Box.y1)then
        Result:= y <= Box.y2;
end;

function PointInBox(P: TPoint; Box: TBox): Boolean;
begin
  Result:= False;
  if(P.x >= Box.x1)then
    if(P.x <= Box.x2)then
      if(P.y >= Box.y1)then
        Result:= P.y <= Box.y2;
end;

function PointToBox(P1, P2: TPoint): TBox;
begin
  Result.x1:= P1.x;
  Result.y1:= P1.y;
  Result.x2:= P2.x;
  Result.y2:= P2.y;
end;

function Point(x, y: Integer): TPoint;
begin
  Result.x:= x;
  Result.y:= y;
end;

function IntToBox(x1, y1, x2, y2: Integer; Box: TBox): TBox;
begin
  Box.x1:= x1;
  Box.y1:= y1;
  Box.x2:= x2;
  Box.y2:= y2;
end;

function AMin(Data: TIntegerArray): Integer;
begin
  Result:= MinIntValue(Data);
end;

function AMinE(Data: TExtendedArray): Extended;
var
  I: Integer;
begin
  Result:= MaxExtended;
  for I:= Low(Data) to High(Data) do
    if(Data[I] < Result)then Result:= Data[I];
end;

function AMax(Data: TIntegerArray): Integer;
begin
  Result:= MaxIntValue(Data);
end;

function AMaxE(Data: TExtendedArray): Extended;
var
  I: Integer;
begin
  Result:= MinExtended;
  for I:= Low(Data) to High(Data) do
    if(Data[I] > Result)then Result:= Data[I];
end;

end.
